# predict_ensemble.py
import paddle
import numpy as np
from models.efficient_time_llm import EfficientTimeLLM
from models.time_series_data import TimeSeriesData
def sliding_window_predict(model, history, time_history, pred_steps=24, window_size=96):
    """
    递归滑动预测
    history: [L, N] 历史数据
    time_history: [L, 2] 时间特征
    pred_steps: 要预测的步数
    """
    predictions = []
    current_input = history[-window_size:]
    current_time = time_history[-window_size:]

    for _ in range(pred_steps):
        # ✅ 显式指定为 float32 类型
        X = paddle.to_tensor(current_input, dtype='float32')
        time_x = paddle.to_tensor(current_time, dtype='int64')

        pred = model(X, time_x)
        pred = pred.numpy().flatten()[-1]

        predictions.append(pred)

        # 滑动窗口
        current_input = np.vstack([current_input[1:], pred])
        current_time = np.vstack([current_time[1:], current_time[-1:] + 1]) % 24  # 模拟时间递增

    return predictions

